﻿#region Namespace imports

using System;
using System.Collections.Generic;
using System.IO;

#endregion

namespace AdventureGame
{
    internal class World
    {
        public static List<Area> _world = new List<Area>();
        public static Dictionary<String, Area> _world2 = new Dictionary<String, Area>();
        public static Int32 explored;
        static public String whichroom = "caverns entrance";

        public static void CampainModeBegin()
        {
            Console.WriteLine("Welcome to Campain Mode!");
            Console.WriteLine();
            Console.WriteLine("You have dared to enter the Caverns of Caldremot!");
            Console.WriteLine("What dangers await you here?");
            ReadMap();
            Explore();
        }

        private static void ReadMap()
        {
            StreamReader stream = new StreamReader(@"Data\map.txt");

            while (!stream.EndOfStream)
            {
                Area area = new Area(stream);
                _world2.Add(area._name.ToLower(), area);
            }
                           
        }

        public static void Explore()
        {
            while (true)
            {
                String nextRoom = _world2[whichroom].movement().ToLower();

                if (_world2.ContainsKey(nextRoom))
                {
                    whichroom = nextRoom;
                }
                else
                {
                    return;
                }
            }
        }

        public static string Input()
        {
            return Console.ReadLine().Trim().ToLower();
        }

        public static void Mormorda1()
        {
            Console.WriteLine();
            Console.WriteLine();

            Console.WriteLine("The trolls scatter at the loss of their leader, you are victourious!");
            Console.WriteLine("There is a great cheer and the faces of all the remaining soldiers are joyous.");
            Console.ReadKey();
            Console.WriteLine("Without warning, a dark figure emerges from the portal");
            Console.WriteLine("The battlefield is suddenly shrouded in shadow. You can barely make out anything.");
            Console.WriteLine("The figure speaks, and his voice sends shivers down your spine and freezes your blood.");
            Console.WriteLine("\"Do you honestly think I needed an army to take what is mine? Did you really belive that defeating this ramshackle band of misbegotten things would save your precious Caverns? You humans amuse me so.\"");
            Console.WriteLine("The soldiers begin to edge back from the figure as it moves closer.");
            Console.ReadKey();
            Console.WriteLine("\"Yes, remember me. Your ancesters seized what was mine so long ago. Remember how you feared me.\"");
            Console.WriteLine("The Commander steps forward. \"You-- You speak of myth. You claim to be a character in storybooks. This is m-mere fantasy.\"");
            Console.WriteLine("The air becomes deathly cold. Several soldiers fall to their knees in agony.");
            Console.ReadKey();
            Console.WriteLine("\"Myth, is it? Trapped for nine centuries on Earth is all it takes to make me myth? That is disappointing. Those of you with the merest shred of intelligence should flee now. The Caverns are of no interest to me. What they lead to is what is mine.\"");
            Console.WriteLine("At this, the soldiers stiffen. They seem to hesitate for a moment... And then they form lines and begin to march toward the dark figure.");
            Console.WriteLine("\"Is this all Espeleth has to defend her kingdom? A pathetic excuse for an army, and no Hero besides. Die now.\"");
            Console.ReadKey();
            Console.WriteLine("With that, there is a roll of thunder and a flash of lighting and you see the most horrible sight you will ever see. The soldiers suddenly stop where they stand and each gives a scream of shuch agony as to raise your hair on end. Then, the flesh begins to rot off of their bodies and they slump toward the ground, all dead.");
            Console.WriteLine("Or, that is what you hoped. With a lurch, each of the bodies rises and begin shambling about, repairing the damage to the troll camp!!!!");
            Console.WriteLine();
            Console.ReadKey();
            Console.WriteLine("\"Ha ha ha ha ha!! Castle Caldremot, Center of Caldria, the connection between the Caverns and the Spirit World, YOU ARE MINE!!!!\"");
            Console.WriteLine("");

            Repopulate();
            Hero.Zombies = true;
            Console.WriteLine();
        }

        static void Repopulate()
        {
            _world2["troll command center"]._postBattle = "You've got to get out of here!";
            _world2["troll command center"]._monsters = "wight";
            _world2["troll command center"]._monsters2 = "zombie";
            _world2["drilling field"]._monsters = "wight";
            _world2["cavern of caldremot: battlefield"]._monsters = "zombie";
            _world2["dark gate"]._monsters = "zombie";
            _world2["dark gate"]._monsters2 = "wight";
            _world2["troll front lines"]._monsters = "zombie";
            _world2["cavern of caldremot: battlefield"]._west = "Decimated Camp";

        }

        public static void Victory()
        {
            Console.WriteLine();
            Console.WriteLine();
            
            Console.WriteLine("A look of surprise crosses Mormorda's face. Then anger, then fear and finally hatred.");
            Console.ReadKey();
            Console.WriteLine("\"It appears you have won the day.\" He coughs and staggers backward. \"You, a mere reincarnation of the original... Bested me. He he he... This is not the end. I... This tale of light... and darkness... will forever be told.... over... a... frozen hearth. Until... Our next encounter.... Son of Aras.\"");
            Console.ReadKey();
            Console.WriteLine("Mormorda vanishes before your eyes.");
            Console.WriteLine("The Queen steps forward and smiles at you.");
            Console.ReadKey();
            Console.WriteLine("\"There is much you do not understand.\" She says with a catch in her voice. \"This world, the connection between it, the Caverns, the Earth and the Spirit world. Mormorda and his legacy. Your own destiny. Mine. My kingdom's. All cannot be explained now, but rest assured, you will know. It is just a matter of time and choices. Your journesy will take you many places, and one day it will lead you here again. I hope to see you again. Until then...\"");
            Console.ReadKey();
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine("You are victorious!!!");
            Console.WriteLine("You completed the game finding {0}% of the world", (explored/_world2.Count)*100);
            Console.WriteLine();
            Console.WriteLine("Your finishing stats are:");
            Console.WriteLine("Level: {0}", Hero.GrabLevel());
            Console.WriteLine("Hp: {0}", Hero.GrabHp());           
            Console.WriteLine("Atk: {0}", Hero.GrabAtk());
            Console.WriteLine("Def: {0}", Hero.GrabDef());
            Console.WriteLine("Eva: {0}", Hero.GrabEva());
            Console.WriteLine("Acc: {0}", Hero.GrabAcc());
            Console.WriteLine("Mag: {0}", Hero.GrabMag());
            Console.WriteLine("Res: {0}", Hero.GrabRes());
            Console.WriteLine("Potions: {0}", Hero.GrabPot());
            Console.WriteLine("Mana potions: {0}", Hero.GrabManaPot());
            Console.WriteLine("Spells: {0}", Hero.GrabSpe());
            Console.WriteLine("Spells Known:");

            if (Hero.SpellBlast)
            {
                Console.WriteLine("\tBlast");
            }

            if (Hero.SpellParalyze)
            {
                Console.WriteLine("\tParalyze");
            }

            if (Hero.SpellPoison)
            {
                Console.WriteLine("\tPoison");
            }

            if (Hero.SpellHeal)
            {
                Console.WriteLine("\tHeal");
            }

            if (Hero.SpellWeaken)
            {
                Console.WriteLine("\tWeaken");
            }

            if (Hero.SpellEnhance)
            {
                Console.WriteLine("\tEnhance");
            }

            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine("Your final score is {0}",
                              ((explored/_world.Count)*100) + (Hero.GrabHp()*10) + (Hero.GrabLevel()*10) +
                              (Hero.GrabSpe()*20));
            Console.ReadKey();
            Console.WriteLine();
            Console.WriteLine("Thank you for playing the Caverns of Caldremot!");
            Console.WriteLine("Rest assured, your journey will lead you to the Caverns and the Kingdom of Caldria beyon again, and when it does, old friends and foes will await you here.");
            Console.WriteLine("Until then...");
        }
    }
}
